package com.dhemery.mack.model.tests;


import static org.junit.Assert.*;

import org.junit.Test;

import com.dhemery.mack.model.Folder;
import com.dhemery.mack.model.Node;

public class FolderTests {

	@Test
	public void defaultFolderHasDefaultName() {
		assertEquals(Folder.DEFAULT_FOLDER_NAME, new Folder().getName());
	}
	
	@Test
	public void hasNodeList() {
		Folder folder = new Folder();

		assertNotNull(folder.getNodes());
	}

	@Test
	public void newFolderHasEmptyNodeList() {
		Folder folder = new Folder();

		assertEquals(0, folder.getNodes().size());
	}

	@Test
	public void remembersAddedNode() {
		Folder folder = new Folder();

		Node node = new Node("");
		folder.addNode(node);

		assertEquals(1, folder.getNodes().size());
		assertTrue(folder.getNodes().contains(node));
	}

	@Test
	public void setsFolderOnAddedNode() {
		Folder folder = new Folder();
		Node node = new Node("");

		folder.addNode(node);

		assertSame(folder, node.getFolder());
	}

	@Test
	public void remembersEachAddedNode() {
		Folder folder = new Folder();

		folder.addNode(new Node(""));
		folder.addNode(new Node(""));
		folder.addNode(new Node(""));

		assertEquals(3, folder.getNodes().size());
	}

	@Test
	public void retainsNodesInTheOrderTheyWereAdded() {
		Folder folder = new Folder();
		Node firstNode = new Node("");
		Node middleNode = new Node("");
		Node lastNode = new Node("");

		folder.addNode(firstNode);
		folder.addNode(middleNode);
		folder.addNode(lastNode);

		assertSame(firstNode, folder.getNodes().get(0));
		assertSame(middleNode, folder.getNodes().get(1));
		assertSame(lastNode, folder.getNodes().get(2));
	}
	
}
